package com.amtf.datafile2;

import java.io.File;
import java.net.URI;

public abstract class DataFile<DC extends DataCatalog<DT, DTD, DFD>, DT extends DataTable<DTD, DFD>, DTD extends DataTableDefinition<DFD>, DFD extends DataFieldDefinition> extends
		File {
	private static final long serialVersionUID = 7203988118567253428L;
	protected DTD definition = null;
	protected DataAccessor<DC, DT, DTD, DFD> dataAccessor = null;

	public DataFile(DTD definition, String pathname) {
		super(pathname);
		this.definition = definition;
	}

	public DataFile(DTD definition, URI uri) {
		super(uri);
		this.definition = definition;
	}

	public DataFile(DTD definition, File file) {
		super(file.getAbsolutePath());
		this.definition = definition;
	}

	public DTD getDefinition() {
		return definition;
	}

	public DC openDataCatalog() throws DataException {
		DC dc = dataAccessor.open();
		dc.setDataTableDefinition(definition);
		return dc;
	}

	public void closeDataCatalog() throws DataException {
		dataAccessor.commit();
		dataAccessor.close();
	}
}
